<!--HIS接口已执行任务查询  -->
<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div class="pagetop">
            <template>
                <div style="width: 100%">
                    <table>
                        <tr>
                            <td>
                                <table style="font-size: 12px" class="table1style">
                                    <tr>
                                        <td>生成日期</td>
                                        <td>
                                            <el-date-picker v-model="createdt1" type="datetime" placeholder="开始日期"
                                                value-format="yyyy-MM-dd HH:mm:ss"> </el-date-picker> 至
                                            <el-date-picker v-model="createdt2" type="datetime" placeholder="结束日期"
                                                value-format="yyyy-MM-dd HH:mm:ss"> </el-date-picker>
                                        </td>
                                        <td>HIS接口事件</td>
                                        <td>
                                            <!-- <el-select v-model="planevent" clearable>
                                                <el-option v-for="item in eventlist" :key="item.codeno" :label="item.codena" :value="item.codeno"> </el-option>
                                            </el-select> -->
                                            <rm-ddl-common datatype="hismethod1" v-model="planevent" width="160px"
                                                :appendtobody="true"></rm-ddl-common>
                                        </td>
                                        <td>执行标志</td>
                                        <td>
                                            <el-select v-model="execflag" clearable>
                                                <el-option label="未执行" value="0"></el-option>
                                                <el-option label="已执行" value="1"></el-option>
                                                <el-option label="待执行" value="2"></el-option>
                                                <el-option label="暂停执行" value="8"></el-option>
                                                <el-option label="执行失败" value="9"></el-option>
                                            </el-select>
                                        </td>
                                        <td>HIS接口</td>
                                        <td>
                                            <el-select v-model="hisinterface" clearable>
                                                <el-option v-for="item in interfacelist" :key="item.his_code"
                                                    :label="item.his_name" :value="item.his_code"> </el-option>
                                                <el-option label="内置系统配置接口" value="RmCloudLis7_Stat"></el-option>
                                                <el-option v-if="$tool.getSession(this.$tool.loginuserno) == 'admin'"
                                                    label="全部接口" value="All"></el-option>
                                            </el-select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>有效标志</td>
                                        <td>
                                            <el-radio-group v-model="validflag">
                                                <el-radio label="a">所有</el-radio>
                                                <el-radio label="0">异常</el-radio>
                                                <el-radio label="1">有效</el-radio>
                                                <el-radio label="9">暂停</el-radio>
                                            </el-radio-group>
                                        </td>
                                        <td>相关单据ID</td>
                                        <td>
                                            <el-input v-model="transid"></el-input>
                                        </td>
                                        <td>相关单据ID1</td>
                                        <td>
                                            <el-input v-model="transid1"></el-input>
                                        </td>
                                        <td>相关单据ID2</td>
                                        <td>
                                            <el-input v-model="transid2"></el-input>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table style="width: 40px; height: 100%; width: 100%">
                                    <tr>
                                        <td width="2000px"></td>
                                        <td>
                                            <el-button type="primary" @click="tablePage.currentPage = 1; QueryPlan()"
                                                icon="el-icon-search">查询</el-button>
                                        </td>
                                        <td>
                                            <el-button @click="RecoverJudge()" icon="el-icon-edit-outline">重新执行</el-button>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>
            </template>
        </div>
        <div class="pagecenter">
            <div class="middle-center" style="height:calc(100% - 50px)">
                <vxe-table :data.sync="HisInterData" :loading="loadingHis" :checkbox-config="{ reserve: true }"
                    :sort-config="{ trigger: 'cell' }" @cell-dblclick="HisDblClick" :cell-class-name="CellClass" border
                    height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow
                    ref="histable" resizable size="mini" show-header-overflow show-overflow="ellipsis"
                    :keyboard-config="keyConfig" :start-index="(tablePage.currentPage - 1) * tablePage.pageSize">
                    <vxe-table-column  type="selection"  width="30px" align="center"></vxe-table-column>
                    <vxe-table-column :field="item.field" :title="item.title" :width="item.width" :key="item.field"
                        v-for="item in HisInterColumn" header-align="center" sortable
                        :sort-width="item.field == 'exec_msec' ? 20 : 0"></vxe-table-column>
                </vxe-table>

            </div>
            <div class="pagerfix">
                <vxe-pager :loading="loadingHis" :current-page="tablePage.currentPage" :page-size="tablePage.pageSize"
                    :page-sizes="[100, 200, 500, 1000, 2000, 5000]" :total="tablePage.total"
                    :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
                    @page-change="handlePageChange">
                </vxe-pager>
            </div>
        </div>

        <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="结果查看" :visible.sync="HisVisible" width="500px"
            style="padding: 5px 5px 5px 5px" top="6vh">
            <el-input type="textarea" autosize="false" v-model="commenttxt" readonly row="5"></el-input>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "MNG144",
    data() {
        return {
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
                isArrow: true
            },
            loadingHis: false,
            HisInterData: [],
            HisInterColumn: [],
            createdt1: "",
            createdt2: "",
            planevent: "",
            eventlist: [],
            execflag: "",
            validflag: "a",
            hisinterface: "",
            interfacelist: [],
            transid: "",
            transid1: "",
            transid2: "",
            HisVisible: false,
            commenttxt: "",
            Now: [],
            tablePage: {
                currentPage: 1,
                pageSize: 100,
                total: 0,
            },
        };
    },
    created() {
        this.InitPageData();
    },
    mounted() { },
    updated() { },
    methods: {
        handlePageChange({ currentPage, pageSize }) {
            this.tablePage.currentPage = currentPage;
            this.tablePage.pageSize = pageSize;
            this.QueryPlan();
        },
        InitPageData() {
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG144",
                    method: "post",
                    data: {
                        action: "InitPageData"
                    }
                })
                .then(res => {
                    this.HisInterColumn = res.RData.Cols;
                    this.Now = res.Now.split("-");
                    this.createdt1 = res.Now + " 00:00:00";
                    this.createdt2 = res.Now + " 23:59:59";
                    this.eventlist = res.codelist;
                    this.interfacelist = res.interlist;
                    this.hisinterface = res.interlist[0];
                    if (this.$tool.getSession(this.$tool.loginuserno) == "admin") this.hisinterface = "All";
                });
        },
        CellClass({ seq, row, rowIndex, $rowIndex, column }) {
            if (column.property == "exec_failcnt") {
                if (row.exec_failcnt > 0) {
                    return "count";
                }
            }
            if (column.property == "valid_flagname") {
                if (row.valid_flag == 0) {
                    return "warn-high";
                }
            }
        },
        QueryPlan() {
            this.loadingHis = true;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG144",
                    method: "post",
                    data: {
                        action: "queryplan",
                        createdt1: this.createdt1,
                        createdt2: this.createdt2,
                        hisinterevent: this.planevent,
                        execflag: this.execflag,
                        validflag: this.validflag,
                        transid: this.transid,
                        transid1: this.transid1,
                        transid2: this.transid2,
                        hisinterface: this.hisinterface,
                        pagesize: this.tablePage.pageSize,
                        currentpage: this.tablePage.currentPage,
                    }
                })
                .then(res => {
                    if (res) {
                        this.tablePage.total = res.total;
                        this.HisInterData = res.Data;
                        this.loadingHis = false;
                    }
                })
                .catch(err => {
                    this.$message.error(err);
                    this.loadingHis = false;
                });
        },
        RecoverJudge() {
            var rows = this.$refs.histable.getSelectRecords();
            if (rows.length == 0) {
                this.$alert("请选择要重新执行的任务!", "提示");
                return;
            }
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG144",
                    method: "post",
                    data: {
                        action: "InitPageData"
                    }
                })
                .then(res => {
                    let nowtime = res.Now.split("-");
                    this.$prompt("请输入密码", "密码校验", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        showCancelButton: false,
                        cancelButtonClass: "el-button el-button--default el-button--small el-button--primary",
                        confirmButtonClass: "el-button el-button--default el-button--small",
                        focusCancelButton: false
                    }).then(({ value }) => {
                        var flag = value == (nowtime[0] - 0) * 3 + (nowtime[1] - 0) * 6 + (nowtime[2] - 0) * 9;
                        if (flag) {
                            this.Recover();
                        } else {
                            this.$message.error("密码错误!");
                        }
                    });
                });
        },
        Recover() {
            var rows = this.$refs.histable.getSelectRecords();
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG144",
                    method: "post",
                    data: {
                        action: "recover",
                        plan_execid: rows
                    }
                })
                .then(res => {
                    if (res.errcode == "1") {
                        this.$message({
                            type: "success",
                            message: "重新执行成功!"
                        });
                        this.QueryPlan();
                    } else {
                        this.$alert(res.errmsg, "提示");
                    }
                });
        },
        HisDblClick({ row, rowIndex, $rowIndex, column }) {
            if (column.property == "exec_comment") {
                this.commenttxt = row.exec_comment;
                this.HisVisible = true;
            }
        }
    }
};
</script>

<style scoped>
::v-deep .warn-high {
    background-color: #ffc0c0;
}

::v-deep .count {
    background-color: yellow;
}

::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
    width: 180px;
}

.pagetop {
    width: 100%;
    height: 105px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 110px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 100%;
    left: 0px;
    right: 0px;
    overflow: auto;
}

.poppagetop {
    width: 100%;
    height: 40px;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    position: absolute;
    border: 1px solid #ccc;
    z-index: 999;
}

.poppagecenter {
    position: absolute;
    top: 50px;
    width: 100%;
    left: 0;
}

.popmiddle-left {
    background-color: aqua;
    position: absolute;
    height: 450px;
    width: 480px;
    left: 0px;
    overflow: auto;
}

.popmiddle-center {
    position: absolute;
    -webkit-box-align: center;
    height: 100%;
    left: 485px;
    right: 485px;
}

.popmiddle-right {
    position: absolute;
    top: 0;
    bottom: 0;
    height: 450px;
    width: 480px;
    right: 0px;
    border: 1px solid #ccc;
}

.table1style tr td {
    padding: 0px 2px 0px 5px;
    white-space: nowrap;
}

.pagerfix {
    height: 40px;
    position: fixed;
    bottom: 40px;
    right: 10px;
    width: 100%;
}</style>